package com.uff.hmstpa.model.service.impl;

import java.util.List;

import com.uff.hmstpa.model.domain.Patient;
import com.uff.hmstpa.model.mediator.ModelMediator;
import com.uff.hmstpa.model.persistence.PatientDAO;
import com.uff.hmstpa.model.persistence.impl.PatientDAOImpl;
import com.uff.hmstpa.model.service.PatientService;
import com.uff.hmstpa.util.exception.BusinessRuleException;

public class PatientServiceImpl implements PatientService {

	private ModelMediator mediator;
	private PatientDAO patientDAO = PatientDAOImpl.getInstance();

	public PatientServiceImpl() {
	}

	public Patient retrievePatient(String cpf) throws BusinessRuleException {
		Patient p = patientDAO.retrieve(cpf);
		
		if(p == null) {
			throw new BusinessRuleException(this, "Nenhum paciente encontrado com o CPF informado.");
		}
		
		return p;
	}
	
	public List<Patient> retrieveAllPatients() {
		return patientDAO.retrieveAllPatients();
	}

	public Patient createPatient(String cpf, String name, int healthplan) {
		patientDAO.persist(cpf, name, healthplan);
		return patientDAO.retrieve(cpf);
	}

	public void deletePatient(String cpf) {
		patientDAO.delete(cpf);
	}

	public void setMediator(ModelMediator mediator) {
		this.mediator = mediator;		
	}

	public ModelMediator getMediator() {
		return this.mediator;
	}

}
